package main

import (
	"github.com/astaxie/beego/logs"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
)

var engine *xorm.Engine

func main() {
	var err error
	engine, err = xorm.NewEngine("mysql", "rtls:BceJpfspdPj3bAWz@(192.168.10.2:3306)/rtls?charset=utf8")
	if err != nil {
		logs.Error("aaaaaaaaaaaaaaaaaa", err.Error())
		return
	}

	_, err = engine.Exec("DROP PROCEDURE if EXISTS alter_column;\ndelimiter $$ \nCREATE PROCEDURE alter_column()\n\tbegin\n\t\t\tif exists (SELECT column_name FROM information_schema.columns WHERE table_schema= DATABASE() AND table_name='rtls_engine' AND column_name='host') then\n\t\t\t\t\t#1、删除 host\n\t\t\t\t\tALTER TABLE rtls_engine DROP COLUMN `host`;\n\t\t\tend if;\n\t\t\tif exists (SELECT column_name FROM information_schema.columns WHERE table_schema= DATABASE() AND table_name='rtls_engine' AND column_name='map_nums') then\n\t\t\t\t\t#2、删除 map_nums\n\t\t\t\t\tALTER TABLE rtls_engine DROP COLUMN `map_nums`;\n\t\t\tend if;\n\t\t\tif exists (SELECT column_name FROM information_schema.columns WHERE table_schema= DATABASE() AND table_name='rtls_engine' AND column_name='engine_ip') then\n\t\t\t\t\t#3、修改 engine_ip 字段为 engine_addr \n\t\t\t\t\tALTER TABLE rtls_engine CHANGE `engine_ip` `engine_addr` VARCHAR(128) NOT NULL COMMENT '引擎地址';\n\t\t\tend if;\n\tend $$\ndelimiter ;\n\nCALL alter_column();\nDROP PROCEDURE if EXISTS alter_column;")
	if err != nil {
		logs.Error(err.Error())
	}

}
